package com.example.logindemo.Pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Msg {

    // 状态码
    private int state;
    // 提示信息
    private String message;

    // 封装有效数据
    private Map<String, Object> data = new HashMap<String, Object>();

    public static Msg success() {
        Msg result = new Msg();
        result.setState(200);
        result.setMessage("成功");
        return result;
    }

    public static Msg fail() {
        Msg result = new Msg();
        result.setState(400);
        result.setMessage("业务异常");
        return result;
    }

    public static Msg error() {
        Msg result = new Msg();
        result.setState(500);
        result.setMessage("接口异常");
        return result;
    }

    public static Msg code(int code){
        Msg result = new Msg();
        result.setState(code);
        result.setMessage("exception");
        return result;
    }

    public Msg add(String key, Object value) {
        this.data.put(key, value);
        return this;
    }


}
